﻿String.prototype.rtrim=function(str){
    return this.replace(/(\s*$)/g,str);
};
$(document).ready(function(){
	getSource();
});
/**
 * 加载数据
 */

function getSource(){
	$("div[class=holder]").myPagination({
		currPage: 1,
		pageNumber: 15,
		cssStyle:'grayr',
		limit:10,
		panel:{
			tipInfo_on:true,
			tipInfo_css:{
				width:"22px",height:'12px'
			}
		},
		ajax: {
		  on: true,
		  url: "queryUserList",
		  dataType: 'json',
		  ajaxStart:function(){
			  ZENG.msgbox.show(" 正在加载中，请稍后...", 6, 10000);
		  },onClick:function(page){
			  $.fn.debug(page);
		  },
		  callback:function(data){
			  ZENG.msgbox.hide(); //隐藏加载提示
			  $.fn.debug(data.source);
			  bindGridList(data);
		  }
		}
	}); 
}
function bindGridList(data){
	$("#total").html('总共找到'+data.total+'条数据');
	var html = "";
	if(data.total > 0){
		$.each(data.source,function(i,user){
			html +='<tr id="web'+i+'" class="tableContent" onclick="'+(data.userId ==1 || user.id!=1 ?"ischecked(this)":"")+'">';// ondblclick="editAjax('+user.id+')"
			html +='<td style="padding-left: 5px; width:150px;">';
			if(data.userId ==1 || user.id!=1){
				html += '<input type="checkbox" name="web" onchange="checkedInput(this)" onclick="ischecked(document.getElementById(\'web'+i+'\'))" id="td'+ i +'" value="'+user.id+'"/>';
			}else{
				html += '超级用户，不能进行操作！';
			}
			html += '</td>';
			html +='<td>'+user.fname+'</td>';
			html +='<td>'+user.fpost+'</td>';
			html +='<td>'+user.fdepartment+'</td>';
			html +='<td>'+user.ftranks+'</td></tr>';
		});
	}else{
		html = "<tr><td colspan='5' align='center'>暂无数据</td></tr>";
	}
	$("#users").html(html);
}
/**
 * 选中子元素
 * @param obj
 */
function check(obj){
	if(obj.checked){
		var checkbox = $("[name='web']");
		checkbox.attr("checked",'true');//全选 
		$("[class='tableContent']").css("background-color","#D8F79D");
	}else{
		$("[name='web']").removeAttr("checked");//取消全选 
		$("[class='tableContent']").css("background-color","");
	}
}
/**
 * 当前选中项
 * @param obj
 */
function checkedInput(obj){
	var id = obj.id.replace("td","");
	if(obj.checked)
		$("#web"+id).css("background-color","#D8F79D");
	else
		$("#web"+id).css("background-color","");
		
}
/**
 * 单击行时，选中的则取消，未选中的则选中
 * @param obj
 */
function ischecked(obj){
	var id = obj.id;
	var trObj = $("#"+id);
	var tdId = "td"+id.replace("web","");
	var objCheck = $("#"+tdId);
	if(objCheck.attr("checked")){
		objCheck.removeAttr("checked");//取消选中 
		trObj.css("background-color","");
	}else{
		objCheck.attr("checked",'true');//选中
		trObj.css("background-color","#D8F79D");
	}
}
/**
 * 获取所有选中的id
 * @returns {Array}
 */
function checkedInfo(){
	var ids = [];
	$("[name='web'][checked]").each(function(){  
		ids.push($(this).val());  
	}); 
	return ids;  
}
/**
 * 添加信息页面
 */

function addUserHtml(){
	var table = '<form action="addUser" method="post" name="userForm" id="userForm" onsubmit="return formIsNull(this);">';
		table += '<div class="tab-page" id="baseinfo" style="display: block;">';
		table += '<table width="450" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">';
	    table += '<tr><th colspan="2"><h2>新增用户信息</h2></th></tr>';
		table += '<tr><td width="70">姓名</td><td><input class="text" name="fname" type="text" id="fname" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
	    table += '<tr><td height="30">用户名</td><td height="30"><input class="text" name="fusername" type="text" id="fusername" value="" size="30"  style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">用户登录名</font></td></tr>';
	    table += '<tr><td height="30">密码</td><td height="30"><input class="text" name="fpasswd" type="password" id="fpasswd" value="000000" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">默认密码为"000000"</font></td></tr>';
	    table += '<tr><td height="30">部门</td><td height="30"><input name="fdepartment" type="text" id="fdepartment" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
	    table += '<tr><td height="30">职位</td><td height="30"><input name="fpost" type="text" id="fpost" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
	    table += '<tr> <td height="30">职称</td><td height="30"><input name="ftranks" type="text" id="ftranks" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
	    table += '<tr><td height="30">简介</td><td height="30"><input name="fintro" type="text" id="fintro" value="&nbsp;" size="50" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
	    table += '</table></div></form>';
	return table;
}

/**
 * 提交保存信息数据
 */
function submitUser(uri){
	if(formIsNull($("#userForm")))
		$("#userForm").ajaxSubmit({
			url:uri,
			type:'post',
			dataType:'json',
			success:function(data){
				$.growlUI('数据保存成功');
				if(uri=="addUser"){
					$("#userForm")[0].reset();
				}else{
					$("#cancel").click();
				}
//				getSource();
				$('a[title=1]').click();
			},
			error:function(msg){
				$.growlUI('数据保存失败'); 
			}
		});
}

/**
 * 添加信息弹出信息
 */
function addUser(){
	var html = addUserHtml();
	var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'userHtmlcloseBtn\').click();"/>&nbsp;&nbsp;&nbsp;<input type="image" alt="Submit" src="/CMS/images/box/submit_button.jpg" class="btn" id="submit" onclick="submitUser(\'addUser\')" />';
	Box("userHtml",490,320,html,footerhtml,910);
}
/**
 * 加载数据
 * @param id
 */
function editAjax(id){
	var data = {"id":id};
	$.ajax({
		url:"queryById",
		data:data,
		type:"post",
		dataType:"json",
		success:function(data){
			bindGridEdit(data);
		},
		error:function(data){
			$.growlUI('数据加载出错'); 
		}
	
	});
}
/**
 * 编辑加载数据
 * @param id
 */
function editUser(id){
	var ids = checkedInfo();
	if(ids.length == 1){
		editAjax(ids[0]);
	}else if(ids.length == 0){
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要修改的信息</div>";	
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editHtmlcloseBtn\').click();"/>';
		Box("editHtml",10,10,html,footerhtml,901);
	}else if(ids.length > 1){
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;只能修改1条信息！</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editHtmlcloseBtn\').click();"/>';
		Box("editHtml",10,10,html,footerhtml,901);
	}
}
/**
 * 绑定编辑数据
 * @param data
 */
function bindGridEdit(data){
	var table = '<form action="updateuser" method="post" name="userForm" id="userForm" onsubmit="return formIsNull(this);">';
	table += '<div class="tab-page" id="baseinfo" style="display: block;">';
	table += '<table width="450" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">';
    table += '<tr><th colspan="2"><h2>修改用户信息</h2></th></tr>';
	table += '<tr><td width="70">姓名</td><td><input name="fname" type="text" id="fname" value="'+data.fname+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><input name="id" type="hidden" id="id" value="'+data.id+'"/></td></tr>';
    table += '<tr><td height="30">用户名</td><td height="30"><input name="fusername" type="text" id="fusername" value="'+data.fusername+'" size="30"  style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">用户登录名</font></td></tr>';
    table += '<tr><td height="30">密码</td><td height="30"><input name="fpasswd" type="password" id="fpasswd" value="'+data.fpasswd+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">默认密码为"000000"</font></td></tr>';
    table += '<tr><td height="30">部门</td><td height="30"><input name="fdepartment" type="text" id="fdepartment" value="'+data.fdepartment+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
    table += '<tr><td height="30">职位</td><td height="30"><input name="fpost" type="text" id="fpost" value="'+data.fpost+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
    table += '<tr> <td height="30">职称</td><td height="30"><input name="ftranks" type="text" id="ftranks" value="'+data.ftranks+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
    table += '<tr><td height="30">简介</td><td height="30"><input name="fintro" type="text" id="fintro" value="'+data.fintro+'" size="50" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
    table += '</table></div></form>';
	var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'userHtmlcloseBtn\').click();"/>&nbsp;&nbsp;&nbsp;<input type="image" alt="Submit" src="/CMS/images/box/submit_button.jpg" class="btn" id="submit" onclick="submitUser(\'updateUser\')" />';
	Box("userHtml",490,320,table,footerhtml,910);
}
/**
 * 删除站点信息
 */
function deleteUser(){
	var ids = checkedInfo();
	if(ids.length > 0){
		var s = "";
	    for(var i=0;i<ids.length ;i++){
	        s +=ids[i]+",";
	    }
	    if(s != ""){
	    	s = s.substring(0,s.length-1) ;
	    }
		var data = {"ids":s};
		$.ajax({
			url:"deleteUser",
			data:data,
			type:"post",
			success:function(data){
				$.growlUI('成功删除数据'+data+'条');
				//location.reload();
//				getSource();
				$('a[title=1]').click();
			},
			error:function(data){
				$.growlUI('数据删除失败'); 
			}
		
		});
	}else{
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要删除的信息</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'deleteHtmlcloseBtn\').click();"/>';
		Box("deleteHtml",10,10,html,footerhtml,901);
	}
}
/**
 * 编辑权限
 */
function editRole(flag){
	var ids = checkedInfo();
	if(ids.length == 1){
		if(flag)
			userSite(ids[0]);
		else
			menuAjax(ids[0]);
	}else if(ids.length == 0){
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要修改的信息</div>";	
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editHtmlcloseBtn\').click();"/>';
		Box("editHtml",10,10,html,footerhtml,901);
	}else if(ids.length > 1){
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;只能修改1条信息！</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editHtmlcloseBtn\').click();"/>';
		Box("editHtml",10,10,html,footerhtml,901);
	}
}
/**
 * 加载菜单信息
 * @param id
 */
function menuAjax(id){
	var data = {"id":id};
	$.ajax({
		url:"../menu/queryAllMenu",
		data:data,
		type:"post",
		dataType:"json",
		success:function(data){
			bindGridMenu(data);
		},
		error:function(data){
			$.growlUI('数据删除失败'); 
		}
	});
}
/**
 * 绑定菜单信息
 * @param data
 */
function bindGridMenu(data){
	var userMenu = data.userMenus;
	var menus = data.menus;
	var checked = "checked='checked'";
	var html = '<form action="editMenu" method="post" name="editMenuForm" id="editMenuForm" onsubmit="return formIsNull(this);">';
	html += '<div class="tab-page" id="baseinfo" style="display: block;"><input type="hidden" value="'+data.userId+'" id="userId">';
	
	$.each(data.parent,function(j,parent){	
		html += '<div style="clear:both;"></div><div style="padding:2px; width:99%; background:url(/CMS/images/thbg_over.gif) no-repeat left top;color: #445055; font-weight: bold;">'+parent.fmenutitle+'</div>';
		$.each(menus,function(k,menu){
			if(parent.id==menu.fparentid){
				if(userMenu != null){
					var bool = true;
					var id = menu.id;
					$.each(userMenu,function(i,usermenu){
						if(menu.id==usermenu.fmenuid){
							bool = false;
							//html += '<span style="margin: 2 15px; width:200px; float : left;">'+menu.fmenutitle+'<input name="menu" type="checkbox" id="id'+i+'" value="'+menu.id+'" '+checked+' onchange="checkMe(this.id)"/>&nbsp;&nbsp;R+W<input name="menu1" type="radio" id="id'+i+'" value="'+menu.id+'" '+checked+' onchange="checkMe(this.id)"/>&nbsp;&nbsp;R<input name="menu1" type="radio" id="id'+i+'" value="'+menu.id+'" '+checked+' onchange="checkMe(this.id)"/></span>';
							html += '<span style="margin: 2 15px; width:270px; float: left;">'+menu.fmenutitle+'&nbsp;&nbsp; R<input name="menu" class="r" type="checkbox" id="r'+id+'" value="'+menu.id+':r" '+(usermenu.freadonly=="r"?checked:"")+' onchange="checkMe(\''+id+'\',\'r\')"/>&nbsp;&nbsp; R+W<input name="menu" class="w" type="checkbox" id="w'+id+'" value="'+menu.id+':w" '+(usermenu.freadonly=="w"?checked:"")+' onchange="checkMe(\''+id+'\',\'w\')"/>&nbsp;&nbsp;';
							html += '&nbsp;&nbsp; C<input name="menu" class="c" type="checkbox" id="c'+id+'" value="'+menu.id+':c" '+(usermenu.freadonly=="c"?checked:"")+' onchange="checkMe(\''+id+'\',\'c\')"/>&nbsp;&nbsp; C+W<input name="menu" class="wc" type="checkbox" id="wc'+id+'" value="'+menu.id+':wc" '+(usermenu.freadonly=="wc"?checked:"")+' onchange="checkMe(\''+id+'\',\'wc\')"/></span>';
							return bool;
						}
					});
					if(bool){
						//html += '<span style="margin:2 15px; width:230px; float : left;">'+menu.fmenutitle+'<input name="menu" type="checkbox" id="id'+k+'" value="'+menu.id+'" onchange="checkMe(this.id)"/></span>';
						html += '<span style="margin: 2 15px; width:270px; float: left;">'+menu.fmenutitle+'&nbsp;&nbsp; R<input name="menu" class="r" type="checkbox" id="r'+id+'" value="'+menu.id+':r" onchange="checkMe(\''+id+'\',\'r\')"/>&nbsp;&nbsp; R+W<input name="menu" class="w" type="checkbox" id="w'+id+'" value="'+menu.id+':w" onchange="checkMe(\''+id+'\',\'w\')"/>&nbsp;&nbsp;';
						html += '&nbsp;&nbsp; C<input name="menu" class="c" type="checkbox" id="c'+id+'" value="'+menu.id+':c" onchange="checkMe(\''+id+'\',\'c\')"/>&nbsp;&nbsp; C+W<input name="menu" class="wc" type="checkbox" id="wc'+id+'" value="'+menu.id+':wc" onchange="checkMe(\''+id+'\',\'wc\')"/></span>';
					}
				}
			}
		});
	});
	html += '</div></form>';
	var	footerhtml='只读模式<input name="all" type="checkbox" id="allr" value="0" onchange="checkAll(this,\'r\')"/>&nbsp;&nbsp;&nbsp;';
	footerhtml += '读写模式<input name="all" type="checkbox" id="allw" value="0" onchange="checkAll(this,\'w\')"/>&nbsp;&nbsp;&nbsp;';
	footerhtml += '审核模式<input name="all" type="checkbox" id="allc" value="0" onchange="checkAll(this,\'c\')"/>&nbsp;&nbsp;&nbsp;';
	footerhtml += '写审模式<input name="all" type="checkbox" id="allwc" value="0" onchange="checkAll(this,\'wc\')"/>&nbsp;&nbsp;&nbsp;';
	footerhtml += '<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'menuHtmlcloseBtn\').click();"/>&nbsp;&nbsp;&nbsp;';
	footerhtml += '<input type="image" alt="Submit" title="保存" src="/CMS/images/box/submit_button.jpg" class="btn" id="submit" onclick="updateUserMenu()" />';
	
	Box("menuHtml",560,320,html,footerhtml,910);
}
/**
 * 取消或选中自己
 * @param obj
 */
function checkMe(id,m){
	var objr = $("#r"+id);
	var objw = $("#w"+id);
	var objrc = $("#c"+id);
	var objwc = $("#wc"+id);
	
	if(m=='r'){
		if(objr.attr("checked")){
			objr.attr("checked",'true');//全选 
			objw.removeAttr("checked");//取消全选 
			objwc.removeAttr("checked");//取消全选 
			objrc.removeAttr("checked");//取消全选 
		}else{
			objr.removeAttr("checked");//取消全选 
		}
	}else if(m=="w"){
		if(objw.attr("checked")){
			objw.attr("checked",'true');//全选 
			objr.removeAttr("checked");//取消全选 
			objwc.removeAttr("checked");//取消全选 
			objrc.removeAttr("checked");//取消全选 
		}else{
			objw.removeAttr("checked");//取消全选 
		}
	}else if(m=="wc"){
		if(objwc.attr("checked")){
			objwc.attr("checked",'true');//全选 
			objr.removeAttr("checked");//取消全选 
			objw.removeAttr("checked");//取消全选 
			objrc.removeAttr("checked");//取消全选 
		}else{
			objwc.removeAttr("checked");//取消全选 
		}
	}else if(m=="c"){
		if(objrc.attr("checked")){
			objrc.attr("checked",'true');//全选 
			objr.removeAttr("checked");//取消全选 
			objwc.removeAttr("checked");//取消全选 
			objw.removeAttr("checked");//取消全选 
		}else{
			objrc.removeAttr("checked");//取消全选 
		}
	}
}
/**
 * 反选
 */
function recheck(){
	$("input[name=menu]").each(function(){
		$(this).attr("checked",!$(this).attr("checked"));
	});
}
/**
 * 全选
 * @param obj
 */
function checkAll(obj,m){
	switch (m) {
		case 'w':
			$("#allr").removeAttr("checked");
			$("#allc").removeAttr("checked");
			$("#allwc").removeAttr("checked");
			break;
		case 'r':
			$("#allw").removeAttr("checked");
			$("#allc").removeAttr("checked");
			$("#allwc").removeAttr("checked");
			break;
		case 'c':
			$("#allr").removeAttr("checked");
			$("#allw").removeAttr("checked");
			$("#allwc").removeAttr("checked");
			break;

		default:
			$("#allr").removeAttr("checked");
			$("#allc").removeAttr("checked");
			$("#allw").removeAttr("checked");
		break;
	}
	if(obj.checked){
		$("[name='menu']").removeAttr("checked");//取消全选 
		var checkbox = $("[class='"+m+"']");
		checkbox.attr("checked",'true');//全选 
	}else{
		$("[class='"+m+"']").removeAttr("checked");//取消全选 
	}
}

function getCheckedVal(){
	var ids = '';
	$("[name='menu'][checked]").each(function(){  
		ids += $(this).val() + ',';  
	});
	if(ids != ""){
		ids = ids.substring(0,ids.length-1) ;
    }
	return ids; 
}
/**
 * 保存操作/修改
 */
function updateUserMenu(){
	var ids = getCheckedVal();
	if(ids != ""){
		var userId = $("#userId").val();
		var data = {"ids":ids,"userId":userId};
		$.ajax({
			url:"../menu/setUserMenu",
			data:data,
			type:"post",
			dataType:"json",
			success:function(data){
				$.growlUI('用户权限设置成功');
				$("#cancel").click();
			},
			error:function(data){
				$.growlUI('用户权限设置失败'); 
			}
		});
	}else{
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要编辑的信息</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editMenuHtmlcloseBtn\').click();"/>';
		Box("editMenuHtml",10,10,html,footerhtml,901);
	}
}
//------------------用户网站管理----------------------------
/**
 * 加载用户网站信息
 * @param id
 */
function userSite(id){
	var data = {"uid":id};
	$.ajax({
		url:"userSite",
		data:data,
		type:"post",
		dataType:"json",
		success:function(data){
			bindGridSite(data);
		},
		error:function(data){
			$.growlUI('数据删除失败'); 
		}
	});
}
function bindGridSite(data){
	var sites = data.sites;
	var userSites = data.userSites;
	var checked = "checked='checked'";
	var html = '<form action="editUserSite" method="post" name="editUserSiteForm" id="editUserSiteForm" onsubmit="return formIsNull(this);">';
	html += '<div class="tab-page" id="baseinfo" style="display: block;"><input type="hidden" value="'+data.userId+'" id="userId">';
	$.each(sites,function(i,site){	
		var bool = true;
		if(userSites != null){
			$.each(userSites,function(j,userSite){
				if(site.id == userSite.fsiteid){
					html += '<span style="margin: 2 15px; width:120px; float : left;">'+site.ftitle+'<input name="menu" type="checkbox" id="id'+i+'" value="'+site.id+'" '+checked+' onchange="ischeck(this.id)"/></span>';
					bool = false;
					return bool;
				}
			});
			if(bool){
				html += '<span style="margin: 2 15px; width:120px; float : left;">'+site.ftitle+'<input name="menu" type="checkbox" id="id'+i+'" value="'+site.id+'" onchange="ischeck(this.id)"/></span>';
			}
		}else{
			html += '<span style="margin: 2 15px; width:120px; float : left;">'+site.ftitle+'<input name="menu" type="checkbox" id="id'+i+'" value="'+site.id+'" onchange="ischeck(this.id)"/></span>';
		}
	});
	html += '</div></form>';
	var	footerhtml='全选<input name="all" type="checkbox" id="all" value="0" onchange="checkSite(this)"/>&nbsp;&nbsp;&nbsp;';
	footerhtml += '<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'userSiteHtmlcloseBtn\').onclick();"/>&nbsp;&nbsp;&nbsp;';
	footerhtml += '<input type="image" alt="Submit" title="保存" src="/CMS/images/box/submit_button.jpg" class="btn" id="submit" onclick="saveUserSite()" />';
	
	Box("userSiteHtml",490,320,html,footerhtml,910);
}
function saveUserSite(){
	var ids = getCheckedVal();
	if(ids != ""){
		var userId = $("#userId").val();
		var data = {"ids":ids,"userId":userId};
		$.ajax({
			url:"saveUserSite",
			data:data,
			type:"post",
			dataType:"json",
			success:function(data){
				$.growlUI('用户网站设置成功');
				$("#cancel").click();
			},
			error:function(data){
				$.growlUI('用户网站设置失败'); 
			}
		});
	}else{
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要编辑的信息</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editUserSiteHtmlcloseBtn\').click();"/>';
		Box("editUserSiteHtml",10,10,html,footerhtml,901);
	}
}
/**
 * 全选
 * @param obj
 */
function checkSite(obj){
	if(obj.checked){
		$("[name='menu']").attr("checked",'true');//全选 
	}else{
		$("[name='menu']").removeAttr("checked");//取消全选 
	}
}
/**
 * 取消或选中自己
 * @param obj
 */
function ischeck(id){
	var obj =$("#"+id);
	if(obj.attr("checked")){
		obj.attr("checked",'true');//全选 
	}else{
		obj.removeAttr("checked");//取消全选 
	}
}